﻿using System;
using CtefCrmImport.Common.Enums;
using CtefCrmImport.Common.Extensions;
using CtefCrmImport.Common.Interfaces;
using CtefCrmImport.Common.Models;

namespace CtefCrmImport.Common.Builders
{
    public class DonationBuilder1 : IEntityBuilder<Donation>
    {
        public Donation BuildEntity(string input)
        {
            var fields = input.Split('\t');

            var address = new Address
            {
                AddressLine1 = fields[9].TrimOrEmpty(),
                AddressLine2 = fields[10].TrimOrEmpty(),
                City = fields[11].TrimOrEmpty(),
                State = fields[12].TrimOrEmpty(),
                Zip = fields[13].TrimOrEmpty()
            };

            var donor = new Donor
            {
                LastName = fields[0].TrimOrEmpty(),
                FirstName = fields[1].TrimOrEmpty(),
                PrimaryEmail = fields[14].TrimOrEmpty(),
                Address = address
            };

            Donation donation = new Donation();
            donation.LineInput = input;
            donation.From = donor;
            donation.FundType = DonationType.GeneralFund;
            donation.PaymentInstrument = PaymentType.Unspecified;
            donation.Date = DateTime.Now;
            donation.GiftAmount = decimal.Parse(fields[4]);
            donation.CompanyMatch = decimal.Parse(fields[5]);
            donation.Purpose = fields[7].TrimOrEmpty();
            donation.RecognitionName = fields[8].TrimOrEmpty();

            return donation;
        }
    }
}
